package ru.averta.notes.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import ru.averta.notes.dao.GoogleSuggestDao;
import ru.averta.notes.domain.GoogleSuggest;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * <code>SiteContentDaoImpl</code>
 *
 * @author fedor.belov (fedor.belov@mail.ru)
 *         Date: 19.09.11 14:41
 */

@Repository
public class GoogleSuggestDaoImpl extends GenericDaoHibernateImpl<GoogleSuggest, Long> implements GoogleSuggestDao {

    @Override
    public List<GoogleSuggest> findSuggestsByUrls(Collection<Long> urls) {
        if (urls == null || urls.isEmpty()) {
            return new LinkedList<GoogleSuggest>();
        } else {
            return createCriteria().createAlias("urls", "u").add(Restrictions.in("u.id", urls))
                    .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
        }
    }
}
